#include "RowSet.h"
#include<sstream>

using namespace std;

RowSet::RowSet(void)
{
	_rowsAffected = 0;
}

bool RowSet::Next()
{
	if (HasNext()) {
		_cur = _next++;
		return true;
	}
	else
		return false;
}

int RowSet::GetInt(int col)
{
	return (*_cur).GetInt(col);
}

std::string RowSet::GetString(int col)
{
	return (*_cur).GetString(col);
}

std::string RowSet::GetMsg()
{
	std::stringstream strStream;
	strStream << _rowsAffected << " rows affected\n";
	return strStream.str();
}

void RowSet::PrintRowSet()
{
	//ofstream fout("selectAnswer.txt");
	//if(!fout)
	//{
		//cout<<"can not open file selectAnswer.txt"<<endl;
		//return ;
	//}
	int num = 0;
	int index = 0;
	int size = (int)this->_rowset.size();
	cout<<"select result num= "<<this->_rowset.size()<<endl;

	for(size_t i = 0; i < this->_columnName.size(); i++)
		cout<<this->_columnName[i]<<" ";
	cout<<endl;
	
	int max = 0;
	if(size > 20) max = 20;
	else
		max = size;
	for(int i = 0; i < max; i ++)
	{
		this->_rowset[index].PrintRecord();
		index++;
	}

	std::string  flag; 
	if(index < size)
	{
		cout<<"More(y/n)";
		getline(cin, flag);
	}
	bool match = false;
	while(flag != "n" && index < size)
	{
		if( (size - index) > 20)  max = 20;
		else
		{
			max = size - index;
			match= true;
		}
		for(int i = 0 ; i < max ; i++)
		{
			this->_rowset[index].PrintRecord();
			index ++;
		}
		if(match) return;
		cout<<"More(y/n)";
		getline(cin, flag);
	}
}

bool RowSet::IsColumnNameEmpty()
{
	if(this->_columnName.size() == 0)
		return true;
	return false;
}

RowSet::~RowSet(void)
{
}
